package com.xcdh.ittools.controller;

import com.api.ittools.entity.ToolDatasource;
import com.api.ittools.query.DbQuery;
import com.xcdh.domain.vo.R;
import com.xcdh.ittools.service.ToolDatasourceService;
import com.xcdh.orm.client.DsClient;
import com.xcdh.orm.entity.OrmDataSource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/toolDs")
public class ToolDsController {
    @Autowired
    private ToolDatasourceService toolDatasourceService ;

    @Autowired
    private DsClient dsClient ;

    @PostMapping("/queryDbs")
    private R queryDbs(@RequestBody ToolDatasource datasource){
        return R.okData(toolDatasourceService.queryDbs(datasource));
    }


    @PostMapping("/queryDatabaseList")
    private R queryDatabaseList(@RequestBody DbQuery query){
        OrmDataSource dataSource = new OrmDataSource() ;
        dataSource.setDsName(query.getDsName());
        return dsClient.findListDataSources(dataSource) ;
    }

    @PostMapping("/queryTableList")
    private R queryTableList(@RequestBody DbQuery query){
        return R.okData(toolDatasourceService.queryTableList(query));
    }

    @PostMapping("/queryColumnList")
    private R queryColumnList(@RequestBody DbQuery query){
        return R.okData(toolDatasourceService.queryColumnList(query));
    }
}
